package cube.utils.db;

/**
 * 存储过程
 * 
 * @author abiao
 */
public class Procedures {

	/**
	 * 自动生成sequence<br>
	 * 调用方法 : call gen_seq('表名', '主键名', '序列名')
	 */
	public static String GENSEQ = "create or replace procedure "
			+ "gen_seq(tablename varchar2, pkname varchar2, seq_name varchar2) as "
			+ "max_id number;" + "seq_num number;" + "begin "
			+ "execute immediate "
			+ "'select max('||pkname||') from '||tablename into max_id;"
			+ "select count(*) into seq_num "
			+ "from user_sequences where sequence_name=''||seq_name||'';"
			+ "if max_id > 0 then " + "if seq_num <> 0 then "
			+ "execute immediate 'drop sequence '||seq_name;" + "end if;"
			+ "execute immediate "
			+ "'create sequence '||seq_name||' increment by 1 "
			+ "start with '||(max_id + 1)||' "
			+ "nomaxvalue nocycle cache 20';" + "end if;" + "end gen_seq;";
}
